package com.ruoyi.wvp.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.wvp.domain.SurveillanceEvent;
import com.ruoyi.wvp.service.ISurveillanceEventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

@Component("removeOneMonthBeforeDataTask")
@Slf4j
public class RemoveOneMonthBeforeDataTask {
    public void start(){
        ISurveillanceEventService surveillanceEventService = SpringUtils.getBean(ISurveillanceEventService.class);
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(1L);
        log.info("定时任务开始执行：{}",localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        LambdaQueryWrapper<SurveillanceEvent> lt = Wrappers.lambdaQuery(SurveillanceEvent.class).lt(SurveillanceEvent::getEventBeginTime, localDateTime);
        surveillanceEventService.remove(lt);
        surveillanceEventService.freeSpace();
    }
}
